package graph_viewer.structure.clustering;

import java.util.*;
import java.awt.*;
import javax.swing.*;

import graph_viewer.animator.*;
import graph_viewer.canvas.*;
import graph_viewer.util.*;
import graph_viewer.structure.*;

/**
 * define tree node
 */
public class Close_Cluster_Strategy extends Graph_Basic_Cluster_Strategy{
	public Close_Cluster_Strategy(){
		Debug.println( "\ttClose_Cluster_Strategy created!", 3 );
	}
	// close the node, set a position.
	public void do_cluster_action( Graph g, Node node, Graph_Canvas graph_canvas  ){	
		Debug.println( "\tClose_Cluster_Strategy do_cluster_action on:" + node, 26 );

		if ( node.is_root() ){
			Debug.println( "\tDo Close_Cluster_Strategy on root!!" + node, 25 );

			return ;//do nothing
		}else{
			node.set_is_closed( true );			
			node.set_is_psuedo( false );
			node.set_is_labelled( true );

			if ( Clustering_Util.has_pseudo_child( node ) ){
				Debug.println( "\tremove_pseudo_child on:" + node, 25 );

				Clustering_Util.remove_pseudo_child( g, node );
			}
			
			ArrayList children	= node.get_children();

			for ( Iterator _i = children.iterator(); _i.hasNext(); ){
				Node child	= (Node)_i.next();
				child.set_is_closed( true );
				child.set_is_labelled( true );
				child.set_DOI( Structure_Util.get_default_doi() );
				child.set_position( null );
			}
			
			//clean psuedo_cluster


		}
		
		Node_Position_Helper.set_leaf_cluster_size( node, graph_canvas.getGraphics() );
	}
	
	public ArrayList build_pre_clustering_animation_metrics( Graph_Canvas graph_canvas, String node_label ){
		ArrayList animator_metrics	 = new ArrayList();

		Graph		a_graph	= graph_canvas.get_graph();
		Node		a_node	= a_graph.search( node_label );

		Node_Position	animation_dest = new Node_Position( a_node.get_position() );		
		
		String child_label	= "";
		for ( Iterator _i = a_node.get_children().iterator(); _i.hasNext(); ){
			Node child	= (Node)_i.next();

			child.set_is_labelled( false );

			Animator_Metrics	a_m	= new Animator_Metrics(	new Motion_Animator(),
													child.get_label(),	
													child.get_position(),
													animation_dest );
		
			animator_metrics.add( a_m );
			
			child_label = child.get_label();
		}
		
		a_node.set_is_closed( true );		
		
		Node_Position_Helper.set_leaf_cluster_size( a_node, graph_canvas.getGraphics() );
		
		Node_Position	
					node_position_clone	= new Node_Position( a_node.get_position() ),
					size_animation_from	= new Node_Position( node_position_clone );

		size_animation_from.set_width( 1 );
		size_animation_from.set_height( 1 );

		a_node.set_is_closed( false );		

		return animator_metrics;
	}	

	public ArrayList build_post_clustering_animation_metrics( Graph_Canvas graph_canvas, String node_label ){
		return null;
	}		

	public String toString(){
		return "CLOSE_STRATEGY";
	}
} 